﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TMIS.DAL
{
    public class Grade
    {
        private Model.ThesisDB db = new Model.ThesisDB();

        #region 对年级表查询数据功能的实现
        /// <summary>
        /// 获取年级表中所有年级名称
        /// </summary>
        /// <returns></returns>
        public string[] Search()
        {
            string[] grade = (from g in db.Grade
                              select g.Name).ToArray();
            return grade;
        }
        /// <summary>
        /// 获取年级表中指定专业名称对应的所有年级
        /// </summary>
        /// <param name="guid">专业名称对应的ID号</param>
        /// <returns></returns>
        public string[] Search(Guid guid)
        {
            string[] grade = (from g in db.Grade
                                   where g.ProfessionID == guid
                                   select g.Name).ToArray();
            return grade;
        }
        /// <summary>
        /// 获取指定年级名称对应的ID号
        /// </summary>
        /// <param name="grade">年级名称</param>
        /// <param name="professionID">专业ID</param>
        /// <returns></returns>
        public Guid Search(string grade,Guid professionID)
        {
            Guid guid = (from g in db.Grade
                         where g.Name == grade&&g.ProfessionID==professionID
                         select g.ID).FirstOrDefault();
            return guid;
        }
        /// <summary>
        /// 获取指定年级名称对应的ID号
        /// </summary>
        /// <param name="grade">年级名称</param>
        /// <returns></returns>
        public Guid Search(string grade)
        {
            Guid guid = (from g in db.Grade
                         where g.Name == grade
                         select g.ID).FirstOrDefault();
            return guid;
        }
        #endregion

        #region 对年级表插入数据功能的实现
        /// <summary>
        /// 将年级信息数据写入到年级表中
        /// </summary>
        /// <param name="grade"></param>
        public void Insert(Model.Grade grade)
        {
            db.Grade.InsertOnSubmit(grade);
            db.SubmitChanges();
        }
        #endregion

        #region 对年级表删除数据功能的实现
        /// <summary>
        ///删除指定的年级信息数据
        /// </summary>
        /// <param name="grade"></param>
        public void Delete(string grade)
        {
            Model.Grade gra = db.Grade.Single(e => e.Name == grade);
            db.Grade.DeleteOnSubmit(gra);
            db.SubmitChanges();
        }
        #endregion
    }
}
